******************************************************************************************************************
*		
*		Partisan Poll Watchers and Electoral Manipulation
*
*		Authors: Sergio Ascencio and Miguel R. Rueda
* 
*		Description: replicates Figures 5, 7 and 8 (Appendix)
*
******************************************************************************************************************



**Figure 5**
cd "C:\Users\mrueda\Documents\MATLAB\Party_delegates\R&R\replication"

import excel pred_best_response_m2d.xls, sheet("Sheet1") firstrow clear
keep if range<=0.4
mkmat range LCI1pan_m pred1pan_m UCI1pan_m LCI2pan_m pred2pan_m UCI2pan_m LCI1pri_m pred1pri_m UCI1pri_m LCI2pri_m pred2pri_m UCI2pri_m, matrix(p_m)
matrix list p_m

coefplot (matrix(p_m[,3]),ci((p_m[,2] p_m[,4]))) (matrix(p_m[,6]),ci((p_m[,5] p_m[,7]))),scheme(s2mono) vertical
coefplot (matrix(p_m[,9]),ci((p_m[,8] p_m[,10]))) (matrix(p_m[,12]),ci((p_m[,11] p_m[,13]))),scheme(s2mono) vertical

import excel pred_best_response_h2d.xls, sheet("Sheet1") firstrow clear
keep if range<=0.8&range>=0.2

mkmat range LCI1pan_h pred1pan_h UCI1pan_h LCI2pan_h pred2pan_h UCI2pan_h LCI1pri_h pred1pri_h UCI1pri_h LCI2pri_h pred2pri_h UCI2pri_h, matrix(p_h)
matrix list p_h

coefplot (matrix(p_h[,3]),ci((p_h[,2] p_h[,4]))) (matrix(p_h[,6]),ci((p_h[,5] p_h[,7]))),scheme(s2mono) vertical
coefplot (matrix(p_h[,9]),ci((p_h[,8] p_h[,10]))) (matrix(p_h[,12]),ci((p_h[,11] p_h[,13]))),scheme(s2mono) vertical


**Figure 6 Appendix**
import excel pred_best_response_m2lsbc2.xls, sheet("Sheet1") firstrow clear
keep if range<=0.4
mkmat range LCI1pan_m pred1pan_m UCI1pan_m LCI2pan_m pred2pan_m UCI2pan_m LCI1pri_m pred1pri_m UCI1pri_m LCI2pri_m pred2pri_m UCI2pri_m, matrix(p_m)
matrix list p_m

coefplot (matrix(p_m[,3]),ci((p_m[,2] p_m[,4]))) (matrix(p_m[,6]),ci((p_m[,5] p_m[,7]))),scheme(s2mono) vertical
coefplot (matrix(p_m[,9]),ci((p_m[,8] p_m[,10]))) (matrix(p_m[,12]),ci((p_m[,11] p_m[,13]))),scheme(s2mono) vertical


import excel pred_best_response_h2lsb2.xls, sheet("Sheet1") firstrow clear
keep if range<=0.8&range>=0.2

mkmat range LCI1pan_h pred1pan_h UCI1pan_h LCI2pan_h pred2pan_h UCI2pan_h LCI1pri_h pred1pri_h UCI1pri_h LCI2pri_h pred2pri_h UCI2pri_h, matrix(p_h)
matrix list p_h

coefplot (matrix(p_h[,3]),ci((p_h[,2] p_h[,4]))) (matrix(p_h[,6]),ci((p_h[,5] p_h[,7]))),scheme(s2mono) vertical
coefplot (matrix(p_h[,9]),ci((p_h[,8] p_h[,10]))) (matrix(p_h[,12]),ci((p_h[,11] p_h[,13]))),scheme(s2mono) vertical


**Figure 7 **

import excel pred_best_response_r&rc.xls, sheet("Sheet1") firstrow clear
keep if range<=0.8&range>=0.2

*Responses to PRD
mkmat range LCIhpri_prdm predhpri_prdm UCIhpri_prdm, matrix(hpri_prdm) 
mkmat range LCImpri_prdm predmpri_prdm UCImpri_prdm, matrix(mpri_prdm)
mkmat range LCIhpan_prdm predhpan_prdm UCIhpan_prdm, matrix(hpan_prdm)
mkmat range LCImpan_prdm predmpan_prdm UCImpan_prdm, matrix(mpan_prdm)
coefplot (matrix(hpri_prdm[,3]),ci((hpri_prdm[,2] hpri_prdm[,4]))) (matrix(mpri_prdm[,3]),ci((mpri_prdm[,2] mpri_prdm[,4]))) (matrix(hpan_prdm[,3]),ci((hpan_prdm[,2] hpan_prdm[,4]))) (matrix(mpan_prdm[,3]),ci((mpan_prdm[,2] mpan_prdm[,4]))),  scheme(s2mono) vertical

import excel pred_best_response_r&rc.xls, sheet("Sheet1") firstrow clear
keep if range<=0.8&range>=0.2
mkmat range LCIhpri_prdh predhpri_prdh UCIhpri_prdh, matrix(hpri_prdh) 
mkmat range LCImpri_prdh predmpri_prdh UCImpri_prdh, matrix(mpri_prdh) 
mkmat range LCIhpan_prdh predhpan_prdh UCIhpan_prdh, matrix(hpan_prdh) 
mkmat range LCImpan_prdh predmpan_prdh UCImpan_prdh, matrix(mpan_prdh)
coefplot (matrix(hpri_prdh[,3]),ci((hpri_prdh[,2] hpri_prdh[,4]))) (matrix(mpri_prdh[,3]),ci((mpri_prdh[,2] mpri_prdh[,4]))) (matrix(hpan_prdh[,3]),ci((hpan_prdh[,2] hpan_prdh[,4]))) (matrix(mpan_prdh[,3]),ci((mpan_prdh[,2] mpan_prdh[,4]))),scheme(s2mono) vertical

*Responses to PRI
import excel pred_best_response_r&rc.xls, sheet("Sheet1") firstrow clear
keep if range<=0.8&range>=0.2
mkmat range LCIhprd_prim predhprd_prim UCIhprd_prim, matrix(hprd_prim)
mkmat range LCImprd_prim predmprd_prim UCImprd_prim, matrix(mprd_prim)
mkmat range LCIhpan_prim predhpan_prim UCIhpan_prim, matrix(hpan_prim)
mkmat range LCImpan_prim predmpan_prim UCImpan_prim, matrix(mpan_prim)
coefplot (matrix(hprd_prim[,3]),ci((hprd_prim[,2] hprd_prim[,4]))) (matrix(mprd_prim[,3]),ci((mprd_prim[,2] mprd_prim[,4]))) (matrix(hpan_prim[,3]),ci((hpan_prim[,2] hpan_prim[,4]))) (matrix(mpan_prim[,3]),ci((mpan_prim[,2] mpan_prim[,4]))),scheme(s2mono) vertical

import excel pred_best_response_r&rc.xls, sheet("Sheet1") firstrow clear
keep if range<=0.8&range>=0.2
mkmat range LCIhprd_prih predhprd_prih UCIhprd_prih, matrix(hprd_prih)
mkmat range LCImprd_prih predmprd_prih UCImprd_prih, matrix(mprd_prih)
mkmat range LCIhpan_prih predhpan_prih UCIhpan_prih, matrix(hpan_prih) 
mkmat range LCImpan_prih predmpan_prih UCImpan_prih, matrix(mpan_prih)
coefplot (matrix(hprd_prih[,3]),ci((hprd_prih[,2] hprd_prih[,4]))) (matrix(mprd_prih[,3]),ci((mprd_prih[,2] mprd_prih[,4]))) (matrix(hpan_prih[,3]),ci((hpan_prih[,2] hpan_prih[,4]))) (matrix(mpan_prih[,3]),ci((mpan_prih[,2] mpan_prih[,4]))),scheme(s2mono) vertical

*Responses to PAN
import excel pred_best_response_r&rc.xls, sheet("Sheet1") firstrow clear
keep if range<=0.8&range>=0.2
mkmat range LCIhprd_panm predhprd_panm UCIhprd_panm, matrix(hprd_panm)
mkmat range LCImprd_panm predmprd_panm UCImprd_panm, matrix(mprd_panm) 
mkmat range LCIhpri_panm predhpri_panm UCIhpri_panm, matrix(hpri_panm) 
mkmat range LCImpri_panm predmpri_panm UCImpri_panm, matrix(mpri_panm)
coefplot (matrix(hprd_panm[,3]),ci((hprd_panm[,2] hprd_panm[,4]))) (matrix(mprd_panm[,3]),ci((mprd_panm[,2] mprd_panm[,4]))) (matrix(hpri_panm[,3]),ci((hpri_panm[,2] hpri_panm[,4]))) (matrix(mpri_panm[,3]),ci((mpri_panm[,2] mpri_panm[,4]))),scheme(s2mono) vertical

import excel pred_best_response_r&rc.xls, sheet("Sheet1") firstrow clear
keep if range<=0.8&range>=0.2
mkmat range LCIhprd_panh predhprd_panh UCIhprd_panh, matrix(hprd_panh)
mkmat range LCImprd_panh predmprd_panh UCImprd_panh, matrix(mprd_panh)
mkmat range LCIhpri_panh predhpri_panh UCIhpri_panh, matrix(hpri_panh) 
mkmat range LCImpri_panh predmpri_panh UCImpri_panh, matrix(mpri_panh)
coefplot (matrix(hprd_panh[,3]),ci((hprd_panh[,2] hprd_panh[,4]))) (matrix(mprd_panh[,3]),ci((mprd_panh[,2] mprd_panh[,4]))) (matrix(hpri_panh[,3]),ci((hpri_panh[,2] hpri_panh[,4]))) (matrix(mpri_panh[,3]),ci((mpri_panh[,2] mpri_panh[,4]))),scheme(s2mono) vertical


*Figure 8 Appendix**
*MLE results
import delimited results_fitc.txt, clear
twoway (scatter best_response first_step, msize(vtiny)) (lfit best_response first_step), ytitle("Best response") leg(off)

*LS results
import delimited results_fit_lsb.txt, clear
twoway (scatter best_response first_step, msize(vtiny)) (lfit best_response first_step), ytitle("Best response") leg(off)

